package com.brook.app.android.filepicker.core;

import android.content.Context;
import android.content.Intent;

import com.brook.app.android.filepicker.ui.FilePickerActivity;
import com.brook.app.android.filepicker.util.ConfigPool;

public class FilePickerConfigRegistry {

    private static FilePickerConfig DEFAULT_CONFIG;

    public static FilePickerConfig getDefaultConfig() {
        if (DEFAULT_CONFIG == null) {
            DEFAULT_CONFIG = createDefaultConfig();
        }
        return DEFAULT_CONFIG;
    }

    public static void setDefaultConfig(FilePickerConfig defaultConfig) {
        DEFAULT_CONFIG = defaultConfig;
    }

    public static FilePickerConfig createDefaultConfig() {
        final FilePickerConfig config = new FilePickerConfig();
        config.addFileProvider(new ImageFileProvider());
        config.addFileProvider(new VideoProvider());
        config.setStartPickerUIDelegate(new IStartPickerUIDelegate() {
            @Override
            public void launchPickerUI(Context context, FilePickerConfig filePickerConfig) {
                Intent intent = new Intent(context, FilePickerActivity.class);
                intent.putExtra(FilePickerActivity.CONFIG_TOKEN, ConfigPool.getInstance().putConfig(filePickerConfig));
                context.startActivity(intent);
            }
        });
        return config;
    }

}
